export default {
	async getOrders(orderStatus) {
		let params=this.searchCondition;
		params.orderStatus=orderStatus;
		let apiUrl = this.apis.getOrders;
		if(orderStatus == 'canceled') {
			apiUrl = this.apis.cancelPage;
		}
		if(orderStatus=='all'){
			params.orderStatus = '';
		}
		let res=await this.httptool.post(apiUrl,params);
		this.tableData = res.data.list;
		this.total=res.data.total;
		
	},
	async getOrderDetail(){
		let res= await this.httptool.post(this.apis.getOrderDetail,{id:this.id});
		this.modelData = res.data;
	},
	async getShippingList(orderid, indentid){
		let params = {
			indentId: orderid,
			indentDetailId:indentid
		};
		let res=await this.httptool.post('logisticsPlanAPI/get',params);
		this.shipTableData = res.data;
		if(this.shipTableData.length>0){
			this.visible=true
		}else{
			this.$message('暂无运货记录！');
		}
	},
	async confirmReceipts(id) {
		let params = {
			id: id
		};
		let res=await this.httptool.post(this.apis.confirmReceipt,params);
		this.$message.success('已确认收货!');
		this.getOrders(this.type);
		
	},
	async orderDeletes(id) {
		let params = {
			id: id
		};
		let res=await this.httptool.post(this.apis.orderDelete,params);
		this.$message.success('删除成功!');
		this.getOrders(this.type);
	},
	orderPreview(self, params, successBack, errorBack) {
		self.httptool.ajaxPost(self.apis.previewOrder, params, function(res) {
			self.tableData = res.data.list;
			self.totalMoney = res.data.priceCount;
			self.closeLoading();
		}, function(res) {
			self.closeLoading();
		});
	},
	orderAdd(self, successBack, errorBack) {
		let params = {};
		params.address = self.params.address;
		params.ids = self.params.ids;
		params.subjectId = self.params.subjectId;
		params.traffickerId = self.params.traffickerId;
		let leavemsgs = [];
		for(let item of self.tableData) {
			let leavemsg = {};
			leavemsg.leavemsg = item.leavemsg;
			for(let car of item.list) {
				leavemsg.id = car.shopCarId;
				leavemsgs.push(leavemsg);
			}
		}
		params.leavemsg = JSON.stringify(leavemsgs);
		self.httptool.ajaxPost(self.apis.orderAdd, params, function(res) {
			if(res.code == 1) {
//				self.$router.replace("orders?type=wait_paid");
				let orderids={};
				orderids.ids=res.data;
				self.httptool.ajaxPost('sign/handSign', orderids, res=>{
					console.log(res);
					if(res.data){
//						self.$router.push(res.data.signUrl);
						window.location.href=res.data.signUrl;
					}
				});
			} else {
				self.$toast('提交失败！');
			}
		});
	},
	
	async cancelApply() {
		let rule = [{
			name: 'applyReason',
			label: '取消原因',
			rule: ['validateEmpty_']
		}];
		if(!this.validatetool.validate(this, this.cancelOrder, rule)) {
			return;
		}
		let res=await this.httptool.post(this.apis.cancelApply,this.cancelOrder);
		this.cancelOrder.applyReason = '';
		this.cancelDiagShow = false;
		this.$message('取消订单!');
		this.getOrders(this.type);
	}
}